import {Body, Controller, Get, Post, Query, UseGuards} from '@nestjs/common';
import {ApiOperation, ApiTags} from "@nestjs/swagger";
import {createCommentDto} from "./dto/create-comment.dto";
import {GetUser} from "@app/common/decorations/getUser.drcorator";
import {AuthGuard} from "@nestjs/passport";
import {CommentsService} from "./comments.service";

@Controller('comments')
@ApiTags('评论')
export class CommentsController {
  constructor(
      private readonly commentsService: CommentsService) {
  }

  @Get()
  @ApiOperation({summary: '获取评论'})
  async index(@Query('query') query: string) {
    return await this.commentsService.getComments(query)
  }

  @Post()
  @UseGuards(AuthGuard("jwt"))
  @ApiOperation({summary: '发表评论'})
  async create(@Body() dto: createCommentDto, @GetUser() user) {
    return await this.commentsService.createComment(dto,user)
  }

}
